home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: seebs@solutions.solon.com (Peter Seebach)
- Newsgroups: comp.lang.c
- Subject: Re: Help! Can't read input from keyboard!
- Date: 2 Apr 1996 18:40:12 -0600
- Organization: Usenet Fact Police (Undercover)
- Message-ID: <4jshdc$q4e@solutions.solon.com>
- References: <4jq0ts$5mh@taniemarie.solon.com> <4jre6e$op1@linet06.li.net>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <4jre6e$op1@linet06.li.net>,
- Jeremy Markman <jeremy@newshost.li.net> wrote:
- >Peter Seebach (seebs@taniemarie.solon.com) wrote:
- >: I guess I thought I knew C, but maybe not. The following program compiles
-
- >Maybe Not...
-
- >First, the sscanf() function will read in input from a string. You did
- >not specify a string, which is why you got an error originally when
- >compiling.
-
- I did *NOT* get an error compiling; the code, as posted originally,
- *does* compile. Did you even *try* it?
-
- Not only did I never call sscanf, but I certainly *did* specify a string;
- I specified "3" as a string.
-
- >Use the getch() function to read in one character
- >at a time from the keyboard, then parse the characters you read in to
- >make sure you are getting the input you are looking for.
-
- This is unfortunately very *bad* advice. getch() is not a function in
- the C language, and is not available on my system.
-
- >Here's a quick example:
-
- >int main()
- > {
- > int ch;
-
- > ch = getch();
- > printf("%c\n",ch);
-
- > return(0);
- > }
-
- This gets
- ld: main.o: undefined symbol _getch()
- on at least one machine.
-
- You should use "getchar" if you want to do this. You will notice that
- getchar does not return characters until the user sends the line; this
- is the only behavior you can have in legal and conforming C, and there's
- no C way to change it. (The behavior of getch() you depend on is specific
- to one OS, and is not the default on many other systems, even ones which
- happen to have a function called getch.)
-
- >Old Code:
- >: int main(void) {
- >: int i = 0;
- >: (void) sscanf, "3", "%d", i;
-
- This compiles just fine, you realize.
-
- >: (void) printf, "%d", i;
- >: return 0;
- >: }
-
- Please do *NOT* post answers if you haven't got a clue what the question was.
-
- And happy April Fools' day...
-
- -s
- --
- Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
- C/Unix wizard -- C/Unix questions? Send mail for help. No, really!
- FUCK the communications decency act. Goddamned government. [literally.]
- The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
-